<!DOCTYPE html>
<html lang="hi">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta http-equiv="X-Ua-Compatible" content="IE=Edge">
  <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
  <title>辅音+辅音的连音变化</title>
  <meta name="description" content="sanskrit,梵文,辅音+辅音,连音变化">
  <meta name="keywords" content="sanskrit,梵文,辅音,Consonants,Vyañjana,辅音+辅音,连音变化">
  <meta property="og:image" content="img/favicon.png">
  <link rel="icon" type="image/png" href="img/favicon.png">
  <link rel="stylesheet" href="script/sanskrit.css?v=1216">
  <link rel="stylesheet" href="script/audio.css?v=1214">
  <style>
    .title { text-align: center; }
    .home > .title { margin-left: 1em; }

    table { border-collapse: collapse; margin: .5em auto; }
    th,td { padding: .1em .5em; vertical-align: middle;
        border-left: 1px solid #eee; border-bottom: 1px solid #eee; }
    th:last-child, td:last-child { border-right: 1px solid #eee; }
    tbody th:nth-last-child(2), tbody td:nth-last-child(2) { border-right: 1px solid #999; }
    th:nth-child(4), td:nth-child(4),
    th:nth-child(5), td:nth-child(5),
    th:nth-child(9), td:nth-child(9) { border-right: 1px solid #ccc; }
    @media screen and (max-width: 600px) {
        body { padding-left: 1px; padding-right: 1px; }
        th,td { padding: 0 .2em; }
    }

    tfoot { font-size: .9em; }
    td.end { color: #117711; font-size: .8em; background-color: #fdfdfd; border-left: 1px solid #999; }
    td.end span.d { font-size: 1.25em; font-weight: bold; }
    tr:nth-child(2) td.end span.d, td.end:has(br) span.d:first-child { font-size: 1.1em; }
    span.d { font-family: "Sanskrit 2003", sans-serif; white-space: nowrap; }
    tfoot span.d { display: inline-block; margin: .1em; padding: 0 .2em;
        border: 1px solid #ddd; border-radius: 2px; background-color: #fdfdfd; }
    tfoot br+span.d { margin-left: 1.02em; }

    tr:not(:first-child) > th { border-top: 1px solid #999; }
    th, tbody tr:last-child td { border-bottom: 1px solid #999; }
    table { border-top: 1px solid #555; border-bottom: 1px solid #555; }
    td small { font-weight: 300; }

    #body > div { font-size: .9em; }
    [data-order].hi { color: #0d66c2; background-color: #eee; }
    [data-toggle="show-end-h"] { font-weight: bold; }
    [data-same] { color: #aaa !important; }

    body:not(.show-end-s) [data-end-s],
    body:not(.show-end-h) [data-end-h] { display: none; }
  </style>
</head>
<body class="show-iast show-end-s">
<div id="top-bar">
  <span class="home" onclick="location.href='./'" title="Home"><img src="img/favicon.png" alt="Home"></span>
  <span data-toggle="show-end-h">止音</span>
  <span data-toggle="show-end-s">s列</span>
  <span data-toggle="show-deva">天城体</span>
  <span data-toggle="show-iast">转写</span>
</div>
<span class="title">辅音+辅音的连音变化</span>
<div id="body"></div>
<script>
  document.body.classList.toggle('show-end-h', document.body.clientWidth > 460)
  document.querySelector('.home').append(document.querySelector('.title'))
</script>
<script src="script/sanscript.es6.js?v=1216"></script>
<script src="script/sanskrit.js?v=1216"></script>
<script>
  const raw = `
    -k -ṭ -t -p -n    -s -r -as -ās -aḥ -āḥ -Vḥ |
    -  -  -  -  -     7-ḥ 7-ḥ 7-aḥ 7-āḥ -   -   -   |k/kh/p/ph- 句尾
    -  -  3-c -  4-ṃś   1-ś 1-ś 1-aś 1-āś 1-aś 1-āś 1-Vś |c- ch- (腭清)
    6-g 6-ḍ 3-j 6-b 4-ñ    -  -  -   -   2-o  2-ā  2-Vr |j- jh- (腭浊)
    -  -  3-ṭ -  4-ṃṣ   1-ṣ 1-ṣ 1-aṣ 1-āṣ 1-aṣ 1-āṣ 1-Vṣ |ṭ- ṭh- (卷清)
    6-g 6-ḍ 3-ḍ 6-b 4-ṇ    -  -  -   -   2-o  2-ā  2-Vr |ḍ- ḍh- (卷浊)
    -  -  -   -  4-ṃs   1-s  1-s  -  -  1-as 1-ās 1-Vs |t- th- (齿清)
    6-g 6-ḍ 6-d_③ 6-b -     -  -  -   -   2-o  2-ā  2-Vr |g/gh/d/dh/b/bh-↲y/v/h- (其余浊等)
    6-g 6-ḍ 6-d 6-b -     -  8① -   -   2-o  2-ā  2-V① |r-
    6-g 6-ḍ 3-l 6-b 4-ṃ/ṃl -  -  -   -   2-o  2-ā  2-Vr |l-
    5-ṅ 5-ṇ 5-n 5-m -   -  -  -   -   2-o  2-ā  2-Vr |m- n- (鼻音)
    -  -  8-c_② - 8-ñ_② - - - -   -   -   -   |ś-
    -  -  -  -  -     -  -  -   -   -   -   -   |ṅ/ñ/ṇ-
    -  -  -  -  -     8-r 8-r 8-o  8-ā  -   -   -   |浊辅-
    9-g 9-ḍ 9-d 9-b 9-nn*    -  -  9-o_'-↲-a   -   9-a  9-ā  9-Vr |元音-`
  .trim().split('\n').map(r => r.trim().replace(/\|.+$/,
      s => s.replace(/ /g, '_')).split(/\s+/));
  const notes = ['注 V：除 a、ā 外的元音。点击单元格有助记高亮提示。',
    '① -r/-Vḥ + r-:　 r/ḥ前的短元音变为长元音，去除r',
    '② -t+ś-: -c ch-，-n+ś-: -ñ ś-/ch-',
    '③ -k/ṭ/t/p + h-：后词气浊化 -ggh-、-ḍḍh-、-ddh-、-bbh-，可分开', '　',
    '1 -s/r/ḥ + 腭卷齿 清：同化为咝音',
    '2 元音ḥ + 辅音：分别变为 -o、-ā、-Vr (切换“止音”显示)',
    '3 -t + 腭卷l：同化',
    '4 -n + 腭卷齿 清：同化为咝音加ṃ↲-n + 腭卷 浊：同区鼻音 ñ、ṇ',
    '5 -k/ṭ/t/p + m/n-：鼻音化',
    '6 -k/ṭ/t/p + 大部分浊音：浊化，遇h-见③',
    '7 -s/r + 其余清辅音：变-ḥ↲-i/u + s：-iṣ、-uṣ',
    "9 -k/ṭ/t/p + 元音: 浊化↲-as+a: -o '-，-as+其余元音: -a↲-S-ṅ/ṇ/n + 元音: 鼻音重复，S为短元音",
  ]

  const iastRe = /[A-Za-zĀ-žḀ-ỹñ'|-]([A-Za-zĀ-žḀ-ỹñ'/| +-]*[A-Za-zĀ-žḀ-ỹñ'|-])?/g, brRe = / *↲ */g
  const iastToDeva = s => '<span class="d">' + (hasBodyCls('show-deva') ?
    s.replace(/[^VS/-]+/g, a => Sanscript.t(a, 'iast', 'devanagari')) : s) + '</span>'

  function hiOrder(event) {
    const elem = (event.target || event).closest('[data-order]')
    if (!elem.classList.contains('hi')) {
      Array.from(document.querySelectorAll('.hi')).forEach(el => el.classList.remove('hi'))
      Array.from(document.querySelectorAll(`[data-order="${elem.dataset.order}"]`)).forEach(el => el.classList.add('hi'))
    }
  }
  function renderBody(_, toggleCls) {
    if (toggleCls === 'show-deva' && hasBodyCls('show-deva')) {
      document.body.classList.remove('show-iast')
    } else if (toggleCls === 'show-iast' && hasBodyCls('show-iast')) {
      document.body.classList.remove('show-deva')
    }
    const table = createElement(document.getElementById('body'), '', 'table')
    const tbody = createElement(table, '', 'tbody')
    raw.forEach((r, ri) => {
      const tr = createElement(tbody, ri === 0 ? 'rh' : 'rd', 'tr')
      r.forEach((text, col) => {
        const html = text.replace(/^[\d|]+|^-$/g, '')
          .replace(/_/g, ' ')
          .replace(iastRe, iastToDeva)
          .replace(brRe, '<br>')
          .replace(/\(.+\)|[①-⑨]/, s => `<small>${s}</small>`);
        const attr = { html: html,
          data_order: /^\d/.test(text) && parseInt(text) + '' || undefined,
          data_end_s: /[sr]$/.test(raw[0][col]) ? 1 : undefined,
          data_end_h: /ḥ$/.test(raw[0][col]) ? 1 : undefined,
          data_same: ri && raw[0][col] === text.replace(/^\d/, '') ? '1' : undefined,
        }
        createElement(tr, text.startsWith('|') ? 'end' : '', ri === 0 ? 'th' : 'td', attr)
        if (attr.data_order === '8' && attr.data_end_s &&
          !attr.data_same && />-[roā]</.test(html)) {
          console.log(html, r[r.length - 1])
          for (let j = 1; j < ri; j++) {
            const cell = tbody.rows[j].cells[col]
            if (!cell.innerHTML && !/ś|清/.test(raw[j][raw[j].length - 1])) {
              cell.innerHTML = html
              cell.dataset.same = '1'
              cell.dataset.order = attr.data_order
            }
          }
        }
      })
    })
    const foot = createElement(table, '', 'tfoot')
    notes.forEach(s => {
      const html = s.replace(iastRe, iastToDeva).replace(brRe, '<br>')
        .replace(/\(.+\)/, s => `<small>${s}</small>`)
      const order = /^[①②]/.test(s) ? ' data-order="8"' : /^③/.test(s) ? ' data-order="6"' :
        /^\d/.test(s) ? ` data-order="${parseInt(s)}"` : '';
      createElement(foot, '', 'tr', {html: `<td colspan="13"${order}>${html}</td>`})
    })

    Array.from(document.querySelectorAll(`[data-order]`)).forEach(el => {
      el.onclick = hiOrder
      if (el.closest('tfoot') && /^\d/.test(el.textContent)) {
        el.onmouseenter = hiOrder
      }
    })
  }
  renderBody()
</script>
</body>
</html>